package com.maopuyu.template;

import com.maopuyu.entity.Series;
import com.maopuyu.entity.Video;
import com.maopuyu.services.SeriesService;
import com.maopuyu.services.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class VideoController {

    @Autowired
    private VideoService videoService;

    @Autowired
    private SeriesService seriesService;

    @GetMapping("videos")
    public String videos(@RequestParam("region") Integer id, Model model) {
        List<Series> serieses = seriesService.findSeriesByRegion(id);
        model.addAttribute("serieses", serieses);
        return "videos/index";
    }

    @GetMapping("video/list")
    public String videoList(@RequestParam("id") Integer id, Model model) {
        List<Video> videos = videoService.findAllBySeriesId(id);
        model.addAttribute("videos", videos);
        return "videos/play";
    }


    @GetMapping("video/play")
    public String detail(@RequestParam("id") Integer id, Model model) {
        Video video = videoService.findVideoById(id);
        model.addAttribute("video", video);
        List<Video> videos = videoService.findAllBySeriesId(video.getSeriesId());
        model.addAttribute("videos", videos);
        return "videos/play";
    }
}
